//
//  CZTabBarController.swift
//  weibo24
//
//  Created by 李文峰 on 16/2/25.
//  Copyright © 2016年 fengten. All rights reserved.
//

import UIKit

class CZTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //实例化控制器
        //设置控件属性 title tabBarItam.image 和seleceImage
        //添加到父控件中
        //        let home = CZHomeViewController()
        //        home.title = "首页"
        //        home.tabBarItem.image = UIImage(named: "tabbar_home")
        //        home.tabBarItem.selectedImage = UIImage(named: "tabbar_home_highlighted")
        //        let nav = UINavigationController(rootViewController: home)
        //
        //        addChildViewController(nav)
        
        addChildViewController(CZHomeViewController(), title: "首页", image: "tabbar_home")
        addChildViewController(CZFindViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(CZMessageViewController(), title: "信息", image: "tabbar_message_center")
        addChildViewController(CZSettingViewController(), title: "设置", image: "tabbar_profile")
        
        //选中无反应  系统默认渲染蓝色
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        //将+按钮添加到tabBar中 (自定义)
        let tabbar = CZTabBar()
        //KVC让自定义的tabBar = tabbar
        setValue(tabbar, forKey: "tabBar")
        
        //为发布按钮添加点击事件
        tabbar.publishButton.addTarget(self, action: "showPublish", forControlEvents: UIControlEvents.TouchUpOutside)
        
    }
    
    func showPublish(){
        print("发布按钮点击事件")
    }
    
    //抽取方法  设置tabBar
    private func addChildViewController(childController: UIViewController,title: String,image:String) {
        //实例化控制器
        //设置属性
        childController.title = title
        childController.tabBarItem.image = UIImage(named: image)
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        //添加到控制器中
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
        
    }
    
    
    
}
